<template>
  <div id="app">
<!--    <transition :name="transitionName">-->
      <keep-alive include="Main,ArticleDetail,UserArticleList,Favorite,ReadHistory">
          <router-view class="Router"/>
      </keep-alive>
<!--    </transition>-->
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      keepAlive: 'Main', // 需要缓存的页面 例如首页
      transitionName: '' // 初始过渡动画方向
    }
  },
  watch: {
    $route (to, from) {
      // 切换动画
      let isBack = this.$router.isBack // 监听路由变化时的状态为前进还是后退
      if (isBack) {
        this.transitionName = 'slide-right'
      } else {
        this.transitionName = 'slide-left'
      }
      // this.$router.isBack = false
    }
  }
}
</script>

<style>
  body{
    margin: 0px;
    padding: 0px;
  }
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
  .slide-right-enter-active,
  .slide-right-leave-active,
  .slide-left-enter-active,
  .slide-left-leave-active {
    will-change: transform;
    transition: all 3.5s;
    position: absolute;
  }
  .slide-right-enter {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
  .slide-right-leave-active {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
  .slide-left-enter {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
  .slide-left-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
</style>
